package com.h3c.web.common.utils;

import java.lang.reflect.Field;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

public class BeanUtil {
	public static void copyProperties(Object source, Object target)
			throws IllegalArgumentException, IllegalAccessException {
		BeanUtils.copyProperties(source, target);
		// 空字符串设置为null
		for (Field f : target.getClass().getDeclaredFields()) {
			f.setAccessible(true);
			if ((f.get(target) instanceof String) && StringUtils.isBlank((String) f.get(target))) {
				f.set(target, null);
			}
		}
	}
}
